#ifndef _OH_COMPONENT_H
#define	_OH_COMPONENT_H
/*******************************************************************************
 **  Name: component.h                                                        **
 **  Description:                                                             **
 **                                                                           **
 **  CDDL: Open Source Initiative (OSI) Approved License                      **
 **                                                                           **
 **  Copyright (c) 2009-2010 Barry "Gian" James  <bjames@munixos.net>         **
 **  All rights reserved.                                                     **
 **                                                                           **
 **  The contents of this file are subject to the terms of the CDDL:          **
 **  Common Development and Distribution License (the "License").             **
 **  You may not use this file except in compliance with the License.         **
 **                                                                           **
 **  You can obtain a copy of the license at $PROJECT_ROOT/LICENSE            **
 **  or http://www.opensolaris.org/os/licensing.  This code is Open Source    **
 **  and you are free to use it within the confines of the license, even      **
 **  for your own closed-source commercial projects, as long as you follow    **
 **  the terms set forth in the CDDL.                                         **
 **                                                                           **
 **  When distributing Covered Code, include this CDDL HEADER in each         **
 **  file and include the License file at $PROJECT_ROOT/LICENSE.              **
 **  If applicable, add the following below this CDDL HEADER, with the        **
 **  fields enclosed by brackets "[]" replaced with your own identifying      **
 **  information: Portions Copyright [yyyy] [name of copyright owner]         **
 **                                                                           **
 ******************************************************************************/

// Modified $DateTime$ by $Author$
#define _component_h_ID    "$Id$"

#include "common.h"
#include "string.h"

enum class ComponentType
{
    computer, power, weapon, sensor, chassis,
    gear, gadget, software, armor, officer, cockpit, max
};

struct ComponentUpgrade
{
    uint8   id;
    ComponentUpgrade * next;
};

struct ComponentQuality
{
    uint8   id;
    ComponentQuality * next;
};

class Component {
public:
    Component();
    Component(const char *n,ComponentType t,uint32 i);
    Component(const Component& orig);
    virtual ~Component();

    //char *  Name(const char *n = NULL) { if (n) droid::string::create(name,n); return name; }
    uint32  ID(uint32 i = 0) { if (i) id = i; return id; }
    ComponentType Type(ComponentType t = ComponentType::max) {
        if (t != ComponentType::max) type = t;
        return type;
    }
    uint8   Version(uint8 v = 0) { if (v) ver = v; return ver; }
    uint8   SlotsFree() { return upgradeSlots[0] - upgradeSlots[1]; }
    uint8   Slots() { return upgradeSlots[0]; }
    uint8   HardPoints(uint8 h) { if (h) hardPoints = h; return hardPoints; }
    uint16  Weight(uint16 w) { if (w) weight = w; return weight; }
    uint32  Cost(uint32 c) { if (c) cost = c; return cost; }

    // TODO upgrades & qualities
    void    AddUpgrade(ComponentUpgrade * u);
    void    AddQuality(ComponentQuality * q);
    ComponentUpgrade *  GetUpgrades() { return upgrades; }
    ComponentQuality *  GetQualities() { return qualities; }

protected:
    char *  name;
    uint32  id;
    ComponentType   type;
    uint8   ver;
    ComponentUpgrade * upgrades;    // installed upgrades
    ComponentQuality * qualities;   // base + upgrade qualities
    uint8   upgradeSlots[2];    // 0=total,1=used
    uint8   hardPoints;      // how many chassis hard points does this component use?
    uint16  weight;         // weight of this component
    Component * next;       // next component in chassis frame component
    uint8   loc;        // if !=ChassisLocation::max component can only be installed in loc
    uint32  cost;       // cost of component
    
    static uint32   nextID;
    static uint32   NextID() { return (++nextID); }
};

#endif	/* _OH_COMPONENT_H */

